{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from MarketDataLoader import MarketDataLoader\n",
    "from time import time\n",
    "from datetime import datetime\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 指定时间范围（回测常用场景）\n",
    "start_dt = datetime(2020, 1, 1)\n",
    "end_dt = datetime.now()\n",
    "\n",
    "# 初始化加载器\n",
    "loader = MarketDataLoader(\n",
    "    token=\"600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f\",\n",
    "    start_date=start_dt,\n",
    "    end_date=end_dt\n",
    ")\n",
    "\n",
    "# 获取数据\n",
    "market_data = loader.get_market_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GDP数据范围: 2020-03-31 00:00:00 ~ 2024-09-30 00:00:00\n",
      "中证1000数据行数: 1899\n"
     ]
    }
   ],
   "source": [
    "# 验证数据时间范围\n",
    "print(\"GDP数据范围:\", market_data['gdp'].index.min(), \"~\", market_data['gdp'].index.max())\n",
    "print(\"中证1000数据行数:\", len(market_data['zz1000']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "2024-09-30    4.8\n",
       "2024-06-30    5.0\n",
       "2024-03-31    5.3\n",
       "2023-12-31    5.2\n",
       "2023-09-30    5.2\n",
       "Name: gdp_yoy, dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "market_data['gdp'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pmi</th>\n",
       "      <th>ppi_yoy</th>\n",
       "      <th>cpi</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2025-02-28</th>\n",
       "      <td>50.2</td>\n",
       "      <td>-2.2</td>\n",
       "      <td>-0.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2025-01-31</th>\n",
       "      <td>49.1</td>\n",
       "      <td>-2.3</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-12-31</th>\n",
       "      <td>50.1</td>\n",
       "      <td>-2.3</td>\n",
       "      <td>0.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-11-30</th>\n",
       "      <td>50.3</td>\n",
       "      <td>-2.5</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-10-31</th>\n",
       "      <td>50.1</td>\n",
       "      <td>-2.9</td>\n",
       "      <td>0.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             pmi  ppi_yoy  cpi\n",
       "date                          \n",
       "2025-02-28  50.2     -2.2 -0.7\n",
       "2025-01-31  49.1     -2.3  0.5\n",
       "2024-12-31  50.1     -2.3  0.1\n",
       "2024-11-30  50.3     -2.5  0.2\n",
       "2024-10-31  50.1     -2.9  0.3"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "market_data['macro'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>vol</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2020-01-02</th>\n",
       "      <td>5603.9331</td>\n",
       "      <td>5682.6426</td>\n",
       "      <td>5586.1399</td>\n",
       "      <td>5676.5579</td>\n",
       "      <td>178712563.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-03</th>\n",
       "      <td>5685.0849</td>\n",
       "      <td>5717.5054</td>\n",
       "      <td>5667.7417</td>\n",
       "      <td>5706.0438</td>\n",
       "      <td>179006818.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-04</th>\n",
       "      <td>5685.0849</td>\n",
       "      <td>5717.5054</td>\n",
       "      <td>5667.7417</td>\n",
       "      <td>5706.0438</td>\n",
       "      <td>179006818.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-05</th>\n",
       "      <td>5685.0849</td>\n",
       "      <td>5717.5054</td>\n",
       "      <td>5667.7417</td>\n",
       "      <td>5706.0438</td>\n",
       "      <td>179006818.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-06</th>\n",
       "      <td>5686.1612</td>\n",
       "      <td>5803.8619</td>\n",
       "      <td>5670.3430</td>\n",
       "      <td>5764.7334</td>\n",
       "      <td>208487509.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 open       high        low      close          vol\n",
       "date                                                               \n",
       "2020-01-02  5603.9331  5682.6426  5586.1399  5676.5579  178712563.0\n",
       "2020-01-03  5685.0849  5717.5054  5667.7417  5706.0438  179006818.0\n",
       "2020-01-04  5685.0849  5717.5054  5667.7417  5706.0438  179006818.0\n",
       "2020-01-05  5685.0849  5717.5054  5667.7417  5706.0438  179006818.0\n",
       "2020-01-06  5686.1612  5803.8619  5670.3430  5764.7334  208487509.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "market_data['zz1000'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import tushare as ts\n",
    "from datetime import  datetime\n",
    "\n",
    "token=\"600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f\"\n",
    "pro = ts.pro_api(token=token)\n",
    "\n",
    "current_q = f\"{datetime.now().year}Q{(datetime.now().month)//3 +1}\"\n",
    "gdp_df = pro.cn_gdp(end_q=current_q, fields='quarter,gdp_yoy')\n",
    "gdp_df.to_csv(\".\\\\data\\\\gdp_data.csv\", index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "today = datetime.now().strftime(\"%Y%m\")\n",
    "cpi_df = pro.cn_cpi(end_m=today, fields='month,nt_yoy')\n",
    "cpi_df.to_csv(\".\\\\data\\\\cpi_data.csv\", index=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "pro = ts.pro_api(token=token)\n",
    "zz1000_df = pro.index_daily(ts_code=\"000852.SH\", start_date='20160101')\n",
    "zz1000_df = zz1000_df.rename(columns={\"trade_date\": \"datetime\"})\n",
    "zz1000_df[\"datetime\"] = pd.to_datetime(zz1000_df[\"datetime\"])\n",
    "zz1000_df.to_csv(\".\\\\data\\\\zz1000_data.csv\",index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "from vnpy_ctastrategy import (\n",
    "    CtaTemplate, StopOrder, TickData, BarData, \n",
    "    TradeData, OrderData, BarGenerator, ArrayManager\n",
    ")\n",
    "import pandas as pd\n",
    "import os\n",
    "from typing import Optional\n",
    "from vnpy.trader.optimize import OptimizationSetting\n",
    "from vnpy_ctastrategy.backtesting import BacktestingEngine\n",
    "from vnpy.trader.setting import SETTINGS\n",
    "import vnpy_tushare\n",
    "from vnpy_tushare.tushare_datafeed import TushareDatafeed\n",
    "from vnpy.trader.object import HistoryRequest\n",
    "from vnpy.trader.constant import Exchange, Interval\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "zz1000_path = 'E:\\\\GitCloneProject\\\\quant25\\\\01Src\\\\vnpy\\\\environment_evaluation\\\\data\\\\zz1000_data.csv'\n",
    "cpi_path = 'E:\\\\GitCloneProject\\\\quant25\\\\01Src\\\\vnpy\\\\environment_evaluation\\\\data\\\\cpi_data.csv'\n",
    "gdp_path = 'E:\\\\GitCloneProject\\\\quant25\\\\01Src\\\\vnpy\\\\environment_evaluation\\\\data\\\\gdp_data.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "engine = BacktestingEngine()\n",
    "engine.set_parameters(\n",
    "    vt_symbol=\"000001.SZSE\",\n",
    "    interval=\"d\",\n",
    "    start=datetime(2024, 1, 1),\n",
    "    end=datetime(2024, 12, 30),\n",
    "    rate=0.3/10000,\n",
    "    slippage=0.2,\n",
    "    size=100,   # 每手数量\n",
    "    pricetick=0.1,\n",
    "    capital=1_000_000,    # 初始资金\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "SETTINGS['datafeed.username'] = \"token\"\n",
    "SETTINGS['datafeed.password'] = \"600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f\"\n",
    "\n",
    "tsengine = TushareDatafeed()\n",
    "req = HistoryRequest(engine.vt_symbol.split('.')[0], Exchange.SZSE, datetime(2024, 1, 1, 0, 0, 0), datetime(2024, 12, 31, 23, 59, 59), Interval.DAILY)\n",
    "data = tsengine.query_bar_history(req)\n",
    "engine.history_data.extend(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# =======================\n",
    "# 数据预处理模块\n",
    "# =======================\n",
    "class MacroDataProcessor:\n",
    "    \"\"\"宏观经济数据预处理器\"\"\"\n",
    "\n",
    "    def __init__(self, gdp_path: str, cpi_path: str):\n",
    "        # 加载并预处理GDP数据\n",
    "        self.gdp_df = self._load_and_process_csv(gdp_path, \"quarter\", \"gdp_yoy\")\n",
    "        # 加载并预处理CPI数据\n",
    "        self.cpi_df = self._load_and_process_csv(cpi_path, \"month\", \"nt_yoy\")\n",
    "\n",
    "    def _load_and_process_csv(self, file_path: str, date_col: str, value_col: str):\n",
    "        \"\"\"通用CSV加载和预处理方法\"\"\"\n",
    "        df = pd.read_csv(file_path, \n",
    "                        parse_dates=[date_col],\n",
    "                        usecols=[date_col, value_col],\n",
    "                        index_col=date_col)\n",
    "        df = df.dropna()  # 删除空值\n",
    "        df = df.sort_index()  # 按日期排序\n",
    "        return df\n",
    "\n",
    "    def get_gdp(self, date: datetime) -> Optional[float]:\n",
    "        target_q = self._get_quarter(date)\n",
    "        return self.gdp_df.loc[target_q, \"gdp_yoy\"].iloc[0] if target_q in self.gdp_df.index else None\n",
    "    \n",
    "    def get_cpi(self, date: datetime) -> Optional[float]:\n",
    "        target_m = date.strftime(\"%Y-%m\")\n",
    "        return self.cpi_df.loc[target_m, \"nt_yoy\"].iloc[0] if target_m in self.cpi_df.index else None\n",
    "    \n",
    "    def _get_quarter(self, date: datetime) -> str:\n",
    "        \"\"\"计算季度字符串（YYYY-QX格式）\"\"\"\n",
    "        quarter = (date.month // 3) + 1\n",
    "        return f\"{date.year}-Q{quarter}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "class MacroMarketStrategy(CtaTemplate):\n",
    "    \"\"\"宏观经济+中证1000指数CTA策略（动态数据匹配版）\"\"\"\n",
    "\n",
    "    # ======== 参数配置 ========\n",
    "    gdp_threshold = 5\n",
    "    cpi_threshold = 1.5\n",
    "    ma10_window = 10\n",
    "    ma30_window = 30\n",
    "    boll_window = 18\n",
    "    boll_dev = 3.4\n",
    "\n",
    "    parameters = [\n",
    "        \"gdp_threshold\",\n",
    "        \"cpi_threshold\",\n",
    "        \"ma10_window\",\n",
    "        \"ma30_window\",\n",
    "        \"boll_window\",\n",
    "        \"boll_dev\",\n",
    "    ]\n",
    "    variables = [\n",
    "        \"gdp_threshold\",\n",
    "        \"cpi_threshold\",\n",
    "        \"ma10_window\",\n",
    "        \"ma30_window\",\n",
    "        \"boll_window\",\n",
    "        \"boll_dev\",\n",
    "        \"boll_up\",\n",
    "        \"boll_down\",\n",
    "    ]\n",
    "\n",
    "    # ======== 数据成员 ========\n",
    "    macro_processor = None  # 宏观经济数据处理器\n",
    "\n",
    "    # ======== 初始化方法 ========\n",
    "    def __init__(self, cta_engine, strategy_name, vt_symbol, setting):\n",
    "        super().__init__(cta_engine, strategy_name, vt_symbol, setting)\n",
    "        self.am = ArrayManager(size=self.ma10_window) \n",
    "        self.bg = BarGenerator(self.on_bar, 1, self.on_daily_update)\n",
    "        \n",
    "        # 初始化宏观经济数据处理器\n",
    "        self.macro_processor = MacroDataProcessor(\n",
    "            gdp_path=gdp_path,\n",
    "            cpi_path=cpi_path\n",
    "        )\n",
    "\n",
    "    # ======== 数据获取 ========\n",
    "    def _fetch_stock_data(self):\n",
    "        \"\"\"获取中证1000日线数据\"\"\"\n",
    "        df = pd.read_csv(zz1000_path)\n",
    "        return df[[\"datetime\", \"open\", \"high\", \"low\", \"close\", \"volume\"]]\n",
    "\n",
    "    # ======== 指标计算 ========\n",
    "    def _calculate_indicators(self, bar: BarData):\n",
    "        \"\"\"计算日线技术指标\"\"\"\n",
    "        self.boll_up, self.boll_down = self.am.boll(self.boll_window, self.boll_dev)\n",
    "\n",
    "    # ======== 信号生成 ========\n",
    "    def _generate_signal(self, bar: BarData):\n",
    "        \"\"\"日线级别信号生成\"\"\"\n",
    "        current_date = bar.datetime\n",
    "        \n",
    "        # 动态获取宏观经济数据\n",
    "        macro = {\n",
    "            'gdp_qoq': self.macro_processor.get_gdp(current_date),\n",
    "            'cpi_yoy': self.macro_processor.get_cpi(current_date),\n",
    "            'timestamp': current_date\n",
    "        }\n",
    "        \n",
    "        if not macro['gdp_qoq'] or not macro['cpi_yoy']:\n",
    "            return False\n",
    "\n",
    "        macro_bull = (macro['gdp_qoq'] > self.gdp_threshold) and (macro['cpi_yoy'] < self.cpi_threshold)\n",
    "        market_bull = (bar.close_price > self.boll_down)\n",
    "\n",
    "        self.write_log(f\"[{current_date.strftime('%Y-%m-%d')}] \"\n",
    "              f\"GDP: {macro['gdp_qoq']:.2f}% | \"\n",
    "              f\"CPI: {macro['cpi_yoy']:.2f}% | \"\n",
    "              f\"Macro Bull: {macro_bull} | \"\n",
    "              f\"Market Bull: {market_bull}\")\n",
    "        return macro_bull and market_bull\n",
    "\n",
    "    # ======== 主逻辑 ========\n",
    "    def on_bar(self, bar: BarData):\n",
    "        \"\"\"日线主逻辑\"\"\"\n",
    "        self.am.update_bar(bar)\n",
    "        self._calculate_indicators(bar)\n",
    "        if self.pos == 0 and self._generate_signal(bar):\n",
    "            self.buy()\n",
    "        elif self.pos > 0:\n",
    "            if bar.close_price < self.boll_down:\n",
    "                self.sell()\n",
    "\n",
    "    def on_init(self):\n",
    "        \"\"\"初始化策略\"\"\"\n",
    "        self.load_bar(30)\n",
    "        self.write_log(\"策略初始化完成\")\n",
    "        self.write_log(f\"CPI数据覆盖范围：{self.macro_processor.cpi_df.index.tolist()}\")\n",
    "        self.write_log(f\"GDP数据覆盖范围：{self.macro_processor.gdp_df.index.tolist()}\")\n",
    "\n",
    "    def on_daily_update(self):\n",
    "        \"\"\"每日宏观参数更新\"\"\"\n",
    "        # 这里可以添加需要每日更新的参数\n",
    "        pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_25392\\3328322264.py:15: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  df = pd.read_csv(file_path,\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_25392\\3328322264.py:15: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
      "  df = pd.read_csv(file_path,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-03-16 16:30:22.520692\t策略初始化完成\n",
      "2025-03-16 16:30:22.520692\t开始回放历史数据\n",
      "2025-03-16 16:30:22.537605\t回放进度：= [0%]\n",
      "2025-03-16 16:30:22.551559\t回放进度：== [10%]\n",
      "2025-03-16 16:30:22.565548\t回放进度：=== [20%]\n",
      "2025-03-16 16:30:22.578469\t回放进度：==== [30%]\n",
      "2025-03-16 16:30:22.591542\t回放进度：===== [40%]\n",
      "2025-03-16 16:30:22.603498\t回放进度：====== [50%]\n",
      "2025-03-16 16:30:22.617338\t回放进度：======= [60%]\n",
      "2025-03-16 16:30:22.621402\t回放进度：======== [70%]\n",
      "2025-03-16 16:30:22.626420\t回放进度：========= [80%]\n",
      "2025-03-16 16:30:22.627413\t回放进度：========== [90%]\n",
      "2025-03-16 16:30:22.627413\t回放进度：=========== [100%]\n",
      "2025-03-16 16:30:22.627413\t历史数据回放结束\n",
      "2025-03-16 16:30:22.627413\t开始计算逐日盯市盈亏\n",
      "2025-03-16 16:30:22.627413\t回测成交记录为空\n",
      "2025-03-16 16:30:22.629332\t逐日盯市盈亏计算完成\n",
      "2025-03-16 16:30:22.629332\t开始计算策略统计指标\n",
      "2025-03-16 16:30:22.633295\t------------------------------\n",
      "2025-03-16 16:30:22.633295\t首个交易日：\t2024-01-02\n",
      "2025-03-16 16:30:22.633295\t最后交易日：\t2024-12-31\n",
      "2025-03-16 16:30:22.633295\t总交易日：\t242\n",
      "2025-03-16 16:30:22.633295\t盈利交易日：\t0\n",
      "2025-03-16 16:30:22.633295\t亏损交易日：\t0\n",
      "2025-03-16 16:30:22.633295\t起始资金：\t1,000,000.00\n",
      "2025-03-16 16:30:22.634291\t结束资金：\t1,000,000.00\n",
      "2025-03-16 16:30:22.634291\t总收益率：\t0.00%\n",
      "2025-03-16 16:30:22.634291\t年化收益：\t0.00%\n",
      "2025-03-16 16:30:22.634291\t最大回撤: \t0.00\n",
      "2025-03-16 16:30:22.634291\t百分比最大回撤: 0.00%\n",
      "2025-03-16 16:30:22.634291\t最大回撤天数: \t0\n",
      "2025-03-16 16:30:22.634291\t总盈亏：\t0.00\n",
      "2025-03-16 16:30:22.634291\t总手续费：\t0.00\n",
      "2025-03-16 16:30:22.634291\t总滑点：\t0.00\n",
      "2025-03-16 16:30:22.634291\t总成交金额：\t0.00\n",
      "2025-03-16 16:30:22.634291\t总成交笔数：\t0\n",
      "2025-03-16 16:30:22.634291\t日均盈亏：\t0.00\n",
      "2025-03-16 16:30:22.634291\t日均手续费：\t0.00\n",
      "2025-03-16 16:30:22.634291\t日均滑点：\t0.00\n",
      "2025-03-16 16:30:22.634291\t日均成交金额：\t0.00\n",
      "2025-03-16 16:30:22.634291\t日均成交笔数：\t0.0\n",
      "2025-03-16 16:30:22.634291\t日均收益率：\t0.00%\n",
      "2025-03-16 16:30:22.634291\t收益标准差：\t0.00%\n",
      "2025-03-16 16:30:22.634291\tSharpe Ratio：\t0.00\n",
      "2025-03-16 16:30:22.634291\tEWM Sharpe：\t0.00\n",
      "2025-03-16 16:30:22.634291\t收益回撤比：\t0.00\n",
      "2025-03-16 16:30:22.634291\t策略统计指标计算完成\n"
     ]
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "mode": "lines",
         "name": "Balance",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x",
         "y": [
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000
         ],
         "yaxis": "y"
        },
        {
         "fill": "tozeroy",
         "fillcolor": "red",
         "mode": "lines",
         "name": "Drawdown",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x2",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "yaxis": "y2"
        },
        {
         "name": "Daily Pnl",
         "type": "bar",
         "xaxis": "x3",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "yaxis": "y3"
        },
        {
         "name": "Days",
         "nbinsx": 100,
         "type": "histogram",
         "x": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0
         ],
         "xaxis": "x4",
         "yaxis": "y4"
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Balance",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Drawdown",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.7350000000000001,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Daily Pnl",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.47000000000000003,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Pnl Distribution",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.20500000000000002,
          "yanchor": "bottom",
          "yref": "paper"
         }
        ],
        "height": 1000,
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "#E5ECF6",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "#E5ECF6",
          "polar": {
           "angularaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "radialaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "yaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "zaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "caxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          }
         }
        },
        "width": 1000,
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ]
        },
        "xaxis2": {
         "anchor": "y2",
         "domain": [
          0,
          1
         ]
        },
        "xaxis3": {
         "anchor": "y3",
         "domain": [
          0,
          1
         ]
        },
        "xaxis4": {
         "anchor": "y4",
         "domain": [
          0,
          1
         ]
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0.7949999999999999,
          1
         ]
        },
        "yaxis2": {
         "anchor": "x2",
         "domain": [
          0.53,
          0.7350000000000001
         ]
        },
        "yaxis3": {
         "anchor": "x3",
         "domain": [
          0.265,
          0.47000000000000003
         ]
        },
        "yaxis4": {
         "anchor": "x4",
         "domain": [
          0,
          0.20500000000000002
         ]
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "engine.add_strategy(MacroMarketStrategy, {})\n",
    "engine.run_backtesting()\n",
    "df = engine.calculate_result()\n",
    "engine.calculate_statistics()\n",
    "engine.show_chart()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vnpy",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
